package com.mar.tech.unify.verticle.log;

import com.mar.tech.unify.RouterVerticle;
import com.mar.tech.unify.bean.ApiHandler;
import com.mar.tech.unify.constants.QueueName;
import com.mar.tech.unify.service.database.DatabaseService;
import com.mar.tech.unify.verticle.BaseVerticle;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.RoutingContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Description: 日志收集 .<br>
 * <p>Created Time: 2020/10/22 11:34 </p>
 *
 * @author <a href="mail to: mengxiangyuancc@gmail.com" rel="nofollow">孟祥元</a>
 */
public class Log4j2Verticle extends BaseVerticle implements RouterVerticle {
    private static final Logger LOGGER = LoggerFactory.getLogger(Log4j2Verticle.class);

    @Override
    public void start() throws Exception {
        databaseService = DatabaseService.createProxy(vertx, QueueName.DATABASE_QUEUE);
        ROUTERS.add(new ApiHandler(HttpMethod.POST, "/log4j2", this::log4j2));
    }

    private void log4j2(RoutingContext routingContext) {
        LOGGER.warn("收集日志:{}", routingContext.getBodyAsString());
        routingContext.response().end();
    }
}
